package com.example.javanewwork.service.impl;

import com.example.javanewwork.entity.Produce;
import com.example.javanewwork.mapper.DeviceMapper;
import com.example.javanewwork.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class DeviceServiceImpl implements DeviceService {


    @Autowired
    private DeviceMapper deviceMapper;
    @Override
    public int test(int i) {
        int ii = deviceMapper.test(i);
        return ii;
    }

    @Override
    public List<Produce> findAlldevice() {
        List<Produce> p = deviceMapper.findAlldevice();
        return p;
    }

    @Override
    public void deleteById(int id) {
        deviceMapper.deleteByid(id);
    }

    @Override
    public void deleteByid(int id) {
        deviceMapper.deleteByid(id);
//        deviceMapper.deleteById(id);

    }

    @Override
    public List<Produce> selectAll() {

        return deviceMapper.selectAll();
    }

    @Override
    public List<Produce> serachByType(String type) {
        List<Produce> produces = deviceMapper.serachByType(type);

        return produces;
    }

    @Override
    public int serachCount(String type, int i) {
        int count = 0;

        count = deviceMapper.serachbroken(type,i);

        return count;
    }

    @Override
    public void modifydevice(Produce produce, int id) {


        String devicename = produce.getDeviceName();
        String devicetype = produce.getDeviceType();
        Integer devicestatus = produce.getDeviceStatus();
        String deviceprice = produce.getDevicePrice();

        deviceMapper.modifydevice(id,devicename,devicetype,devicestatus,deviceprice);
    }

    @Override
    public void addNewdevice(Produce produce) {


        String devicename = produce.getDeviceName();
        String devicetype = produce.getDeviceType();
        Integer devicestatus = produce.getDeviceStatus();
        String deviceprice = produce.getDevicePrice();


            deviceMapper.insertNewDevice(devicename,devicetype,devicestatus,deviceprice);

    }

//    @Override
//    public void testdelete(int p) {
//
//        deviceMapper.deleteByid(p);
//    }
}
